package com.atguigu;

import org.apache.spark.SparkConf;
import org.apache.spark.sql.SparkSession;

/**
 * @author yhm
 * @create 2022-12-26 14:24
 */
public class Test09_Hive {
    public static void main(String[] args) {

        // 修改系统用户名  获取执行权限
        System.setProperty("HADOOP_USER_NAME","atguigu");

        // 1. 创建sparkConf配置对象
        SparkConf conf = new SparkConf().setAppName("sql").setMaster("local[*]");

        // 2. 创建sparkSession连接对象
        // 开启hive的支持
        SparkSession spark = SparkSession.builder()
                .enableHiveSupport()
                .config(conf).getOrCreate();

        // 3. 编写代码
        spark.sql("show tables").show();

        spark.sql("create table if not exists user(id int,name string)");
        spark.sql("insert into user values(10,'san')");

        spark.sql("select * from user").show();

        // 4. 关闭sparkSession
        spark.close();
    }
}
